#include "Location.h"

#include <U8g2lib.h>


#define U8G2_SCL 30 //5
#define U8G2_SDA 31 //4


L76XLocation lc76g;

/* OLED构造函数，按需修改即可 */
//U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/U8G2_SCL, /* data=*/U8G2_SDA, /* reset=*/U8X8_PIN_NONE);

bool isGsp = false;

void displayWelcome(const char *str, int hig=0) {
  //u8g2.clearBuffer();
  /* 将字符串显示在屏幕中央 */
 // u8g2.drawUTF8(u8g2.getDisplayWidth() / 2 - u8g2.getUTF8Width(str) / 2, (u8g2.getDisplayHeight() / 2 + u8g2.getMaxCharHeight() / 2) + hig, str);
 // u8g2.sendBuffer();
}

void printDateTime(TinyGPSDate &d, TinyGPSTime &t)
{
  if (!d.isValid())
  {
    Serial.print(F("********** "));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
    Serial.print(sz);
  }
  
  if (!t.isValid())
  {
    Serial.print(F("******** "));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
    Serial.print(sz);
  }
  Serial.println("");
  //printInt(d.age(), d.isValid(), 5);
  //smartDelay(0);
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  lc76g.setBaudrate(115200);
  //u8g2.setFont(u8g2_font_wqy12_t_gb2312);
 // u8g2.begin();
 // u8g2.enableUTF8Print();
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("Hello World!!");
  //displayWelcome("Hello World!!",0);
  //displayWelcome("找到定位数据", 0);
  TinyGPSPlus gps = lc76g.getGPS();
  printDateTime(gps.date, gps.time);
  if (gps.location.isValid()) {
    String location = String(gps.location.lat()) + ":" + String(gps.location.lng());
    Serial.println(location);
    displayWelcome(location.c_str(), 10);
  }
  //delay(1000);
}
